package com.abc;
import java.sql.*;

class MysqlCon{
	
public static void main(String args[]){

try{
	
Class.forName("com.mysql.jdbc.Driver");


System.out.println("Connecting to database...");
System.out.println("Creating DATABASE...");

Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/USER_INFO","root","root");

System.out.println("Creating statement...");
Statement stmt=con.createStatement();


/*System.out.println("Creating DATABASE...");
String sql1="CREATE DATABASE USERS";
stmt.executeUpdate(sql1);
*/



/*String sql1="CREATE DATABASE USERS";
stmt.executeUpdate(sql1);
*/


System.out.println("Creating table USER");
stmt.executeUpdate("create table USER(USER_ID BIGINT(10) null auto_increment primary key,USER_NAME varchar(64),EMAIL varchar(128),FIRST_NAME varchar(32),LAST_NAME varchar(32),PASSWORD varchar(128),ACTIVE_FLAG varchar(2),CREATED_BY VARCHAR(11) NULL, CREATED_DATE DATETIME NULL,MODIFIED_BY VARCHAR(45) NULL, DOB DATE NULL,POINTS BIGINT(10) NULL,NUM_BUSINESS BIGINT(10)  NULL)");

System.out.println("inserting into table ...");
stmt.executeUpdate("insert into user(USER_ID,USER_NAME,EMAIL,FIRST_NAME,LAST_NAME,PASSWORD,ACTIVE_FLAG,CREATED_BY,CREATED_DATE,MODIFIED_BY ,DOB ,POINTS,NUM_BUSINESS) values(1,'admin','chand@gmail.com','chandini','haridas','chd','y','chandini','1991-01-01 10:10:00','chandini','1940-01-01',10,10)");
stmt.executeUpdate("insert into user(USER_ID,USER_NAME,EMAIL,FIRST_NAME,LAST_NAME,PASSWORD,ACTIVE_FLAG,CREATED_BY,CREATED_DATE,MODIFIED_BY ,DOB ,POINTS,NUM_BUSINESS) values(2,'user','chandana@gmail.com','chandana','N','c123','y','chandini','1991-06-05 10:50:50','chandana','1944-10-10',45,100)");
stmt.executeUpdate("insert into user(USER_ID,USER_NAME,EMAIL,FIRST_NAME,LAST_NAME,PASSWORD,ACTIVE_FLAG,CREATED_BY,CREATED_DATE,MODIFIED_BY ,DOB ,POINTS,NUM_BUSINESS) values(3,'admin','chand@gmail.com','chandini','haridas','chd','y','chandini','1991-01-01 10:10:00','chandini','1940-01-01',177,1000)");
stmt.executeUpdate("insert into user(USER_ID,USER_NAME,EMAIL,FIRST_NAME,LAST_NAME,PASSWORD,ACTIVE_FLAG,CREATED_BY,CREATED_DATE,MODIFIED_BY ,DOB ,POINTS,NUM_BUSINESS) values(4,'admin','chand@gmail.com','chandini','haridas','chd','y','chandini','1991-01-01 10:10:00','chandini','1940-01-01',189,109)");
stmt.executeUpdate("insert into user(USER_ID,USER_NAME,EMAIL,FIRST_NAME,LAST_NAME,PASSWORD,ACTIVE_FLAG,CREATED_BY,CREATED_DATE,MODIFIED_BY ,DOB ,POINTS,NUM_BUSINESS) values(5,'admin','chand@gmail.com','chandini','haridas','chd','y','chandini','1991-01-01 10:10:00','chandini','1940-01-01',1000,108)");


System.out.println( "USER_ID: \t USER_NAME: \t EMAIL: \t FIRST_NAME: \tLAST_NAME \tPASSWORD \tACTIVE_FLAG \tCREATED_BY \t,CREATED_DATE \t,MODIFIED_BY \t,DOB \t,POINTS \t,NUM_BUSINESS \t ");

String sql;
sql = "SELECT * FROM user";
ResultSet rs=stmt.executeQuery(sql);


while(rs.next()) {

 System.out.print(rs.getInt("USER_ID"));
 System.out.print("\t \t "+ rs.getString("USER_NAME"));
 System.out.print("\t\t "+ rs.getString("EMAIL"));
 System.out.print("\t"+ rs.getString("FIRST_NAME"));
 System.out.print("\t"+ rs.getString("LAST_NAME"));
 System.out.print("\t"+ rs.getString("PASSWORD"));
 System.out.print("\t"+ rs.getString("ACTIVE_FLAG"));
 System.out.print("\t\t"+ rs.getString("CREATED_BY"));
 System.out.print("\t\t"+ rs.getDate("CREATED_DATE"));
 System.out.print(rs.getTime("CREATED_DATE"));
 System.out.print("\t\t"+rs.getString("MODIFIED_BY"));
 System.out.print("\t\t"+rs.getDate("DOB"));
 System.out.print("\t\t"+ rs.getInt("POINTS"));
 System.out.print("\t\t"+ rs.getInt("NUM_BUSINESS"));

System.out.println(" ");
}


rs.close();

stmt.close();
con.close();

}catch(Exception e){ System.out.println(e);}

}
}